function toggle_more_details(resultID){	
	//toggling the divs
	toggle_display('more_details_' + resultID);
	toggle_display('less_details_' + resultID);
	
}

function toggle_version_full_content(page_ID){
	toggle_display('version_full_content_' + page_ID);
	var e = document.getElementById("button_full_content_" + page_ID);
	var text = e.textContent || e.innerText;
	if (text == "Show content")
		document.getElementById("button_full_content_" + page_ID).innerHTML = "Hide content";
	else
		document.getElementById("button_full_content_" + page_ID).innerHTML = "Show content";
}

function toggle_version_metadata(page_ID){
	toggle_display('version_metadata_' + page_ID);
	var e = document.getElementById("button_metadata_" + page_ID);
	var text = e.textContent || e.innerText;
	if (text == "Show metadata")
		document.getElementById("button_metadata_" + page_ID).innerHTML = "Hide metadata";
	else
		document.getElementById("button_metadata_" + page_ID).innerHTML = "Show metadata";
}

function showAdvancedSearch(){
	var elements = document.getElementsByName("advancedSearch");
	for (var i = 0; i < elements.length; i++){
		var e = elements.item(i);
		if (e.style.display=="none")
			e.style.display = "";
		else
			e.style.display="none";
	}
}

function toggle_version_snippets(page_ID){
	toggle_display('version_snippets_' + page_ID);
	var e = document.getElementById("button_snippets_" + page_ID);
	var text = e.textContent || e.innerText;
	if (text == "Show snippets")
		document.getElementById("button_snippets_" + page_ID).innerHTML = "Hide snippets";
	else
		document.getElementById("button_snippets_" + page_ID).innerHTML = "Show snippets";
}


function toggle_display(el) {
	if (document.getElementById(el) == null)
		return;
	if (document.getElementById(el).style.display == "none") {
		document.getElementById(el).style.display = "block";
	} else {
		document.getElementById(el).style.display = "none";		
	}
}

function setSourceCookie()
{
	var sel = document.getElementById('sourceList');
	if (sel != null)
	{
		var value = sel.options[sel.selectedIndex].value;
		var c_name = "wikipages_source";
		var exdays = 1000;
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + exdays);
		var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
		document.cookie=c_name + "=" + c_value + "; path=/";
		
		//location.reload(true);
		//reload
		document.getElementById("searchForm1").submit();
	}
}

function setSource(){
	var value = getCookie("wikipages_source");
	var sel = document.getElementById('sourceList');
	for (i = 0; i < sel.options.length; i++)
		if (sel.options[i].value == value)
			sel.options[i].selected = "selected";
	
	//alert("Set source: " + value);
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
	return null;
}

function showEvents(pid, totalp){
	for (var j = 1; j <= totalp; j++){
		var e = document.getElementById("event_pages_link_" + j);
		if (e != null){
			e.innerHTML = j;
			if (j == pid)
				e.innerHTML = "[" + j + "]";
		}
		
		for (var i = 1; i <= 10; i++){
			var e = document.getElementById("event_" + (j * 10 - 10 + i));
			if (e != null){
				e.style.display = "block";
				if (j != pid)
					e.style.display = "none";
			}			
		}
	}
}

function showWikiPages(pid, totalp){
	for (var j = 1; j <= totalp; j++){
		var e = document.getElementById("wiki_pages_link_" + j);
		if (e != null){
			e.innerHTML = j;
			if (j == pid)
				e.innerHTML = "[" + j + "]";
		}
		for (var i = 1; i <= 10; i++){
			var e = document.getElementById("result_" + (j * 10 - 10 + i));
			if (e != null){
				e.style.display = "block";
				if (j != pid)
					e.style.display = "none";
			}
		}
	}
}

function validate_dates(){
	var fromDate = new Date(document.getElementById("fromDatePick").value);
	var toDate = new Date(document.getElementById("toDatePick").value);
	if (fromDate != null && toDate != null && fromDate.valueOf() > toDate.valueOf())
		alert("Please check input dates!");
}